﻿IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[P_CMS_DBTableCount]') AND type IN (N'P', N'PC'))
DROP PROCEDURE [P_CMS_DBTableCount]
GO


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[P_CMS_DBTableCount]') AND type IN (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'
--统计数据库表的行数
CREATE PROCEDURE [P_CMS_DBTableCount]
    @TableName NVARCHAR(50)
AS 
    BEGIN
        SELECT 
                rows
        FROM    sys.sysindexes
        WHERE   id = OBJECT_ID(@TableName)
    END

' 
END
GO


IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[P_CMS_DBCount]') AND type IN (N'P', N'PC'))
DROP PROCEDURE [P_CMS_DBCount]
GO


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[P_CMS_DBCount]') AND type IN (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'

--统计数据库表的行数
CREATE PROCEDURE [P_CMS_DBCount]

AS 
    BEGIN
        SELECT  a.name ''Key'',
                b.rows ''Value''
        FROM    sysobjects a
                INNER JOIN sysindexes b ON a.id = b.id
        WHERE   a.type = ''u''
                AND b.indid IN ( 0, 1 )
                AND a.name NOT IN ( ''sysdiagrams'', ''__MigrationHistory'' )
        ORDER BY a.name
    END 
' 
END
GO